﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace DrawIO45.Models.DrawIOs
{
    [XmlRoot("mxfile")]
    public class MXFile
    {
        [XmlAttribute("host")]
        public string Host { get; set; } = "Electron";

        [XmlAttribute("agent")]
        public string Agent { get; set; } = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36";

        [XmlAttribute("version")]
        public string Version { get; set; } = "24.7.17";

        [XmlElement("diagram")]
        public List<Diagram> Diagram { get; set; }
    }

    public class Diagram
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("mxGraphModel")]
        public MxGraphModel MxGraphModel { get; set; }
    }


    public class MxGraphModel
    {
        [XmlAttribute("dx")]
        public string Dx { get; set; } = "1434";

        [XmlAttribute("dy")]
        public string Dy { get; set; } = "884";

        [XmlAttribute("grid")]
        public string Grid { get; set; } = "1";

        [XmlAttribute("gridSize")]
        public string GridSize { get; set; } = "10";

        [XmlAttribute("guides")]
        public string Guides { get; set; } = "1";

        [XmlAttribute("tooltips")]
        public string Tooltips { get; set; } = "1";

        [XmlAttribute("connect")]
        public string Connect { get; set; } = "1";

        [XmlAttribute("arrows")]
        public string Arrows { get; set; } = "1";

        [XmlAttribute("fold")]
        public string Fold { get; set; } = "1";

        [XmlAttribute("page")]
        public string Page { get; set; } = "1";

        [XmlAttribute("pageScale")]
        public string PageScale { get; set; } = "1";

        [XmlAttribute("pageWidth")]
        public string PageWidth { get; set; } = "827";

        [XmlAttribute("pageHeight")]
        public string PageHeight { get; set; } = "1169";

        [XmlAttribute("math")]
        public string Math { get; set; } = "0";

        [XmlAttribute("shadow")]
        public string Shadow { get; set; } = "0";

        [XmlElement("root")]
        public Root Root { get; set; }
    }

    public class Root
    {
        [XmlElement("mxCell")]
        public List<MxCell> MxCells { get; set; } = new List<MxCell>();
    }

    public class MxCell
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("parent")]
        public string Parent { get; set; }

        [XmlAttribute("value")]
        public string Value { get; set; }

        [XmlAttribute("style")]
        public string Style { get; set; }

        [XmlAttribute("vertex")]
        public string Vertex { get; set; }

        [XmlAttribute("edge")]
        public string Edge { get; set; }

        [XmlAttribute("source")]
        public string Source { get; set; }

        [XmlAttribute("target")]
        public string Target { get; set; }

        [XmlElement("mxGeometry")]
        public List<MxGeometry> MxGeometries { get; set; }
    }

    public class MxGeometry
    {
        [XmlAttribute("x")]
        public string X { get; set; }

        [XmlAttribute("y")]
        public string Y { get; set; }

        [XmlAttribute("width")]
        public string Width { get; set; }

        [XmlAttribute("height")]
        public string Height { get; set; }

        [XmlAttribute("as")]
        public string As { get; set; }

        [XmlAttribute("relative")]
        public string Relative { get; set; }

        [XmlArray]
        public List<MxPoint> MxPoints { get; set; }
    }

    public class MxPoint
    {
        [XmlAttribute("x")]
        public string X { get; set; }

        [XmlAttribute("y")]
        public string Y { get; set; }

        [XmlAttribute("as")]
        public string As { get; set; }
    }
}
